home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.08 Aug 91 / Browser sources / CBrowserPane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-19  |  2.7 KB  |  89 lines  |  [TEXT/KAHL]

  1. /******************************************************/
  2. /*                                                                                                      */
  3. /*    CBrowserPane.c                                                                      */
  4. /*                                                                                                      */
  5. /*    Written in Think C version 4.0.2                                  */
  6. /*    Based on CStarterPane.c                                                        */
  7. /*                                                                                                      */
  8. /*    Allen Stenger    January 1991                                              */
  9. /*                                                                                                      */
  10. /******************************************************/
  11.  
  12. #include "CBrowserPane.h"
  13.  
  14. #define FONTNUMBER    4    /* Monaco */
  15. #define FONTSIZE        9
  16.  
  17. void CBrowserPane::IBrowserPane(CView *anEnclosure, 
  18.                             CBureaucrat *aSupervisor,
  19.                             short aWidth, short aHeight,
  20.                             short aHEncl, short aVEncl,
  21.                             SizingOption aHSizing, 
  22.                             SizingOption aVSizing,
  23.                             /* added parameters */
  24.                             char **theDataH, 
  25.                             short theLineCt, 
  26.                             long **theLineStartsH)
  27. {
  28.     FontInfo    theFontInfo;        /* from GetFontInfo             */
  29.     Rect            panoRect;                /* panorama rectangle         */
  30.     short            thisLineLength,    /* length of current and     */
  31.                         maxLineLength;    /* longest line in                 */
  32.                                                         /* **itsDataH                             */
  33.     long            i;                            /* loop control                     */
  34.     
  35.     itsDataH = theDataH;
  36.     itsLineCt = theLineCt;
  37.     itsLineStartsH = theLineStartsH;
  38.     
  39.     CPanorama::IPanorama(anEnclosure, aSupervisor, 
  40.                             aWidth, aHeight,
  41.                             aHEncl, aVEncl, aHSizing, aVSizing);
  42.     Prepare();
  43.     TextFont(FONTNUMBER);
  44.     TextSize(FONTSIZE);
  45.     GetFontInfo( &theFontInfo );
  46.     itsLineHeight = theFontInfo.ascent +
  47.                                     theFontInfo.descent +
  48.                                     theFontInfo.leading;
  49.                                     
  50.     /* get maximum line length - needed for horizontal    */
  51.     /* scrolling control                                                                */
  52.     maxLineLength = 1;
  53.     for (i=0; i<itsLineCt; i++) {
  54.         thisLineLength = (*theLineStartsH)[i+1] - 
  55.                                             (*theLineStartsH)[i];
  56.         if (thisLineLength > maxLineLength)
  57.         maxLineLength = thisLineLength;
  58.         }
  59.         
  60.     /* set up extents of scrolling controls (panorama)     */
  61.     SetRect(&panoRect,0,0,maxLineLength,itsLineCt);
  62.     SetScales(theFontInfo.widMax,itsLineHeight);
  63.     SetBounds(&panoRect);
  64. }
  65.  
  66. void CBrowserPane::Draw(Rect *area)
  67. {
  68.     short    firstLine,lastLine;
  69.     short    i;            /* loop control */
  70.     
  71.     /* Get first and last line numbers to draw.                    */
  72.     /* We will draw an extra line at the top so that         */
  73.     /* if we scroll upward the descenders will be            */
  74.     /* available for scrolling.                                                 */
  75.     firstLine = (*area).top / itsLineHeight;
  76.     if (firstLine < 1) firstLine = 1;
  77.     lastLine = 1 + (*area).bottom / itsLineHeight;
  78.     if (lastLine > itsLineCt) lastLine = itsLineCt;
  79.     
  80.     for (i=firstLine; i<=lastLine; i++) {
  81.         MoveTo(0,i*itsLineHeight);
  82.         DrawText(*itsDataH+(*itsLineStartsH)[i-1],0,
  83.                             (*itsLineStartsH)[i]-
  84.                                 (*itsLineStartsH)[i-1]);
  85.         /* note that we do not expand tabs - this could     */
  86.         /* be added if desired                                                         */
  87.         }
  88. }
  89.